;(function () {
	$("button").click(function() {
		login();
	});
	
	function login(){
		var username = $("#username").val();
		var password = $("#password").val();
		
		if(isEmpty(username)){
			layer.tips('请输入账号', '#username');return;
		}
		if(isEmpty(password)){
			layer.tips('请输入密码', '#password');return;
		}
		
		var data = {
	        'username': username,
	        'password': password
		}
		
	    $.ajax({
	        url: AJAX_URL_USER + 'api/auth/jwt/token',
	        type: 'post',
        	contentType: "application/json",
	        data: JSON.stringify(data),
	        dataType:'JSON',
	        success: function (data) {
	            if(data.code == 0 && data.data != ""){
	            	localStorage.setItem("token", data.data)
	            	window.location.href = 'index.html';
	            }
	            else {
        			layer.msg(data.msg);
	            }
	        },
	        error: function(error) {
        		layer.msg("登录异常"+JSON.stringify(error));
	        }
	    });
	}
}());
